package com.uchiha.nova.mainService.wrapper;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.uchiha.nova.core.model.entity.OrgInfoEntity;
import com.uchiha.nova.core.model.vo.OrgInfoVO;
import com.uchiha.nova.core.tool.support.BaseEntityWrapper;
import com.uchiha.nova.core.tool.util.SpringUtil;
import com.uchiha.nova.mainService.service.IOrgInfoService;

import java.util.List;
import java.util.stream.Collectors;
/**
 * 组织机构 包装类,返回视图层所需的字段
 *
 * @author Uchihashiamu
 */
public class OrgInfoWrapper extends BaseEntityWrapper<OrgInfoEntity, OrgInfoVO>  {
  
  IOrgInfoService orgInfoService = SpringUtil.getBean(IOrgInfoService.class);
  
	public static OrgInfoWrapper build() {
		return new OrgInfoWrapper();
 	}

	@Override
	public OrgInfoVO entityVO(OrgInfoEntity orgInfoEntity) {
		OrgInfoVO orgInfoVO = new OrgInfoVO();
		BeanUtil.copyProperties(orgInfoEntity, orgInfoVO);

		return orgInfoVO;
	}
	public List<OrgInfoVO> listVO(List<OrgInfoEntity> list) {
		List<OrgInfoVO> collect = list.stream().map(item -> {
            OrgInfoVO orgInfoVO = new OrgInfoVO();
		    BeanUtil.copyProperties(item, orgInfoVO);			
			return orgInfoVO;
		}).collect(Collectors.toList());
		return collect;
    // return ForestNodeMerger.merge(collect);
	}
  
  	@Override
	public IPage<OrgInfoVO> pageVO(IPage<OrgInfoEntity> pages) {
		IPage<OrgInfoVO> page = pages.convert(item->{
            OrgInfoVO orgInfoVO = new OrgInfoVO();
		    BeanUtil.copyProperties(item, orgInfoVO);			
			return orgInfoVO;
		});
		return page;
	}
}
